<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<link href="${ctx}/styles/treeSelect.css" type='text/css' rel='stylesheet'>
<style type="text/css">
<!--
.title {
	text-align: center;
	border-bottom: 1px solid #a9bfd3;
	padding: 5px 0px 3px 0px;
	background: url(${ctx}/scripts/extjs/resources/images/default/toolbar/bg.gif);
}

.input{
	border: 0px;
	border-bottom: 1px solid #C0C0C0;
	padding: 0px 5px 0px 5px;
	width: 125px;
}
-->
</style>
<title>编辑用户</title>
</head>
<body>
<div class="x-panel-body">
<s:form action="user/save.do" id="save" validate="true" method="POST" enctype="multipart/form-data">
<s:hidden name="model.id" id="uId" />
<s:hidden name="model.version" />
<s:hidden name="model.type" id="modelType"/>
<s:hidden name="model.status" />
<%
	String selfEdit = (String)request.getAttribute("selfEdit");
	if(selfEdit == null){
		selfEdit = request.getParameter("selfEdit");
		request.setAttribute("selfEdit", selfEdit);
	}
%>
<s:hidden name="selfEdit" />
<table align="center" width="600">
  <tr>
    <td align="right"><%@ include file="/common/messages.jsp"%></td>
  </tr>
</table>
<table align="center" width="600" cellpadding="0" cellspacing="0" style="border: 1px solid #99BBE8; border-bottom: 0px;" >
 <tr>
   <td style="padding: 5px 0px 2px 5px; line-height: 30px;">
     &nbsp;用户类别：
     <s:if test="model.type == 1">
       <span style="color:red; font-weight:bold;">&nbsp;公司员工</span>
     </s:if>
     <s:elseif test="model.type == 2">
		<span style="color:red; font-weight:bold;">&nbsp;分销商<br></span>
		&nbsp;所属地区：
		省<select id="province" name="province" onchange="changeCity(this.value)" style="width:120px;"></select>&nbsp;
		市<select id="city" name="city" onchange="changeCounty(this.value)" style="width: 150px;"></select>&nbsp;
		区县<select id="county" name="county" style="width:120px;"></select>
		<script type="text/javascript" src="${ctx}/pages/area/area.js"></script>
		<script type="text/javascript">
			setupArea('${model.areaCode}');
			
			function changeCity(parentCode){
				setupCity(parentCode, "", "");
			}
			
			function changeCounty(parentCode){
				setupCounty(parentCode, "");
			}
		</script>
     </s:elseif>
     <s:elseif test="model.type == 3">
      <span style="color:red; font-weight:bold;">&nbsp;终端客户</span>
     </s:elseif>
     <s:else>
       <span style="color:red; font-weight:bold;">&nbsp;用户类型错误</span>
     </s:else>
   </td>
 </tr>
</table>
<table align="center" width="600" cellpadding="0" cellspacing="0" style="border: 1px solid #99BBE8;" >
  <tr>
  	<td width="300" valign="top" style="border-right: 2px solid #99BBE8;">
  		<div class="title"><b>用 户 照 片</b></div>
  		<div style="height: 270px; padding-top: 10px ; text-align: center;">
  			<div id="photoDiv">
  			<s:if test="model.photo!=null">
		  		<img id="photo" height="240" width="180" src="${ctx}${model.photo}"><br>
		  		&nbsp;&nbsp;<span style="cursor: pointer;" onclick="delPhoto('${model.id}')">删除照片<img src="${ctx}/images/icons/delete.gif"></span>
  			</s:if>
  			<s:else>
  				<img id="photo" height="240" width="180" src="${ctx}/images/icons/noSupervisor.gif"><br>
  			</s:else>
  			</div>
  		</div>
  		<div style="border-top: 1px dashed #99BBE8; padding-top: 10px;">
  		  &nbsp;&nbsp;选择照片：<s:file id="userPhoto" name="userPhoto" cssClass="FileText checkImg"></s:file><br>
  		  <span id="imgMsg"></span>
  		</div>
  	</td>
    <td width="300" valign="top">
    	<div class="title"><b>主 要 信 息</b></div>
	    <table width="300" cellpadding="0" cellspacing="0" border="0">
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">登录帐号：</td>
	        <td width="230">
	          <s:if test="model.isSys == 1">
			    <s:textfield name="model.loginId" id="loginId" cssClass="input" title="系统用户不可修改！" disabled="true"/>
			  </s:if>
			  <s:else>
			    <s:textfield name="model.loginId" id="loginId" cssClass="input userName required"/>&nbsp;<font color="red">*</font>
			  </s:else>
			  <span id="denglu">&nbsp;</span>
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">登录密码：</td>
	        <td width="230">
	          <s:password name="model.password" id="pwd" cssClass="input required"/>&nbsp;<font color="red">*</font>
	        </td>
	      </tr>
	     <tr height="25px" valign="bottom">
	        <td width="70" align="right">确认密码：</td>
	        <td width="230">
	          <s:password name="model.confirmPwd" id="repwd" cssClass="input passwordCheck required"/>&nbsp;<font color="red">*</font>
	          <span id="pswd">&nbsp;</span>
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">真实姓名：</td>
	        <td width="230">
	          <s:textfield name="model.name" cssClass="input"/>
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">性&nbsp;&nbsp;&nbsp;&nbsp;别：</td>
	        <td width="230">
	          <s:radio list="sexMap" name="model.sex" cssStyle="border:0px;" />
	        </td>
	      </tr>
	      <s:if test="model.type == 1">
	      <s:if test="#attr.selfEdit != 'Y'">
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">所属部门：</td>
	        <td width="230">
	          <div id="comboxWithTree" style="float:left; border: 0px;"></div>&nbsp;<font color="red">*</font>
			  <span id="deptTip"></span>
			  <s:hidden name="deptId" id="deptId" cssClass="deptCheck"/>
	        </td>
	      </tr>
	      </s:if>
	      </s:if>
	      <tr><td colspan="2" height="10px"></td></tr>
	    </table>
	    <div class="title" style="border-top: 1px solid #a9bfd3;">联 系 方 式</div>
	    <table width="300" cellpadding="0" cellspacing="0" border="0">
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">手　　机：</td>
	        <td width="230">
			  <s:textfield name="model.mobile" id="mobile" cssClass="input mobileCheck"/>&nbsp;<font color="red">*</font>
			  <span id="mobileTip">用于短信接收</span>
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">固定电话：</td>
	        <td width="230">
	          <s:textfield name="model.hTel" cssClass="input" />
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">OICQ：</td>
	        <td width="230">
	          <s:textfield name="model.qq" cssClass="input" />
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">MSN：</td>
	        <td width="230">
	          <s:textfield name="model.msn" cssClass="input" />
	        </td>
	      </tr>
	      <tr height="25px" valign="bottom">
	        <td width="70" align="right">电子邮件：</td>
	        <td width="230">
	          <s:textfield name="model.email" id="email" size="25" cssClass="input regEmail"/>
	        </td>
	      </tr>
	         <tr height="25px" valign="bottom">
	        <td width="70" align="right">邮　　编：</td>
	        <td width="230">
			  <s:textfield name="model.zip" cssClass="input" />
	        </td>
	      </tr>
	         <tr height="25px" valign="bottom">
	        <td width="70" align="right">地　　址：</td>
	        <td width="230">
			  <s:textfield name="model.address" cssClass="input" cssStyle="width:200px;"/>
	        </td>
	      </tr>
	      <tr><td colspan="2" height="10px"></td></tr>
	    </table>
      </td>
    </tr>
</table>
<br>
<table width="600" align="center">
  <tr>
    <td align="left">
	<input type="submit" value="保　存" style="padding:4px 5px 2px 5px;" class="title">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="reset" value="重　置" style="padding:4px 5px 2px 5px;" class="title">
    </td>
  </tr>
</table>
</s:form>
<s:hidden name="model.dept.id" id="modelDeptId"/>
</div>
<script type="text/javascript" src="${ctx}/pages/admin/dept/edit.js"></script>
<script type="text/javascript">
<s:if test="model.type == 1">
  <s:if test="#attr.selfEdit != 'Y'">
	Ext.onReady(function() {
		var dtree = new DeptTree({
			url : '/admin/dept/deptTree.do',
			initValue : '${model.dept.name}',
			el : 'comboxWithTree',
			innerTree :'inner-tree',
			onclick : function(nodeId) {
				//alert(nodeId);
			  Ext.get('deptId').dom.value = nodeId;
			}
		});
		dtree.init();	
	}); 
  </s:if>
</s:if>
$(function() {
    //验证密码一致性
	$.validator.addMethod("passwordCheck", function(value, element) {
        var res;
        var pwd1 = document.getElementById('pwd').value;
  		var pwd2 = document.getElementById('repwd').value;
  		if(pwd1 != null & pwd2 != null & pwd1 != '' & pwd2 != '') {
  			if(pwd1 != pwd2) {
  				res = "err";
  				document.getElementById('pswd').innerHTML = '<font color="red">密码不一致!</font>';
  			}else{
  				res = "ok";
  				document.getElementById('pswd').innerHTML = '&nbsp;';
  			}
  		}
        return res != "err";
    },"");
    
    //验证用户名
	$.validator.addMethod("userName", function(value, element) {
        var res;
        var userName = document.getElementById('loginId').value;
        var userId = document.getElementById('uId').value;
     	/**
     	var re = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-\u4e00-\u9fa5]+$/;
     	var result = re.exec(userName);
     	if (result != null) {
       		document.getElementById('denglu').innerHTML = '请填写登录名(仅限字母、数字、横线和下划线。)';
     	}else {
        	document.getElementById('denglu').innerHTML = '<font color="red">'+'仅限字母、数字、横线和下划线，请重新输入。'+'</font>';
     	}
     	*/
     	if (userName != null && userName != ""){
     	   var u = encodeURI('${ctx}/security/user/checkName.do');
      	   $.ajax({
			 url: u,
			 type: 'post',
			 async : false,
			 dataType: 'json',
			 data: {userName : userName, userId : userId},
			 success: function(rst, textStatus){
				res = rst.result;
				if (rst.result == "exist") {
       	   			document.getElementById('denglu').innerHTML ='<font color="red">'+userName+'</font>存在!';
       	    	}else {
       	    		document.getElementById('denglu').innerHTML = '&nbsp;';
       	    	}
			 }
	  	   });
	  	   return res != "exist";
	  	 }
  	  },"");
	//部门验证
	$.validator.addMethod("deptCheck", function(value, element) {
        var res;
        var deptId = document.getElementById('deptId').value;
  		if(deptId == null || deptId == '') {
			res = "err";
			document.getElementById('deptTip').innerHTML = '&nbsp;<font color="red">'+'未选择部门'+'</font>';
  		}else{
  			res = "od";
			document.getElementById('deptTip').innerHTML = '&nbsp;';
  		}
        return res != "err";
    },"");
	
	//手机验证
	$.validator.addMethod("mobileCheck", function(value, element) {
        var res;
        var mobile = document.getElementById('mobile').value;
  		if(mobile != null && mobile.length > 0) {
  	  	  	if(isNaN(mobile)){
	  	  	  	res = "err";
				document.getElementById('mobileTip').innerHTML = '<font color="red">格式错误</font>';
  	  	  	}else{
	  	  		if (mobile.length != 11){
					res = "err";
					document.getElementById('mobileTip').innerHTML = '<font color="red">长度错误:</font>' + mobile.length;
	  	  	  	}else {
	  	  	  		res = "ok";
		  	  		document.getElementById('mobileTip').innerHTML = '用于短信接收';
	  	  	  	} 
  	  	  	}
  		}else{
  			res = "err";
			document.getElementById('mobileTip').innerHTML = '<font color="red">填写手机号</font>';
  		}
        return res != "err";
    },"");
	
	$.validator.addMethod("checkImg", function(value, element) {
        var res;
        var allImg = "*.gif; *.jpg; *.png";
        if (value != null && value.length > 0){
        	imgExt = value.substring(value.lastIndexOf("."), value.length).toLowerCase();
        	imgRight = allImg.indexOf(imgExt) != -1;
        	if (!imgRight){
        		res = "err";
	        	document.getElementById('imgMsg').innerHTML = '<font color="red">&nbsp;&nbsp;文件格式错误,只允许:' + allImg + '</font>';
        	}else{
        		document.getElementById('imgMsg').innerHTML = '&nbsp;';
        	}
        }
        return res != "err";
    },"");
	
	$.validator.addMethod("checkCity", function(value, element) {
        var res;
        if (value == null || value == 0){
        	res = "err";
        	document.getElementById('cityMsg').innerHTML = '<font color="red">&nbsp;请选择</font>';
       	}else{
       		document.getElementById('cityMsg').innerHTML = '&nbsp;';
       	}
        return res != "err";
    },"");
    
  	//验证用户邮箱
  	/** 
	$.validator.addMethod("regEmail", function(value, element) {
        var res;
        var emailStr = document.getElementById('email').value;
        var userId = document.getElementById('uId').value;
		var r = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (emailStr != null && emailStr.length > 0){
			if (r.test(emailStr)) {
				document.getElementById('usemail').innerHTML = '&nbsp;&nbsp;常用的电子邮箱';
		      		$.ajax({
					url: '${ctx}/security/user/checkEmail.do',
					type: 'post',
					async : false,
					dataType: 'json',
					data: {emailStr : emailStr, userId : userId},
					success: function(rst, textStatus){
						res = rst.result;
						if (rst.result == "exist") {
		      	   		  		document.getElementById('usemail').innerHTML = '<b><font color="red">' + emailStr + '</font>已存在!</b>';
		      	   		}
					}
				});//异步调用结束
				return res != "exist";
			} else {
				document.getElementById('usemail').innerHTML = '<font color="red">邮件地址格式错误!</font>';
				return false;
			}
		}else{
			document.getElementById('usemail').innerHTML = '&nbsp;&nbsp;常用的电子邮箱';
		}
		return true;
  	  },"");*/
	}); 
	
	function delPhoto(id){
		modelId = id;
		  $.ajax({
	    		url: '${ctx}/security/user/deleteUserPhoto.do',
	    		type: 'post',
	    		dataType: 'json',
	    		data: {id : modelId},
	    		success: function(rst, textStatus){
	    			if (rst != null){
    					document.getElementById("photoDiv").style.display = "none";
	    			}
	    		}
	    	  });
	}

	/** ready */
	$(document).ready(function() {
		$("#save").validate();
	});
	
	var userId = "${model.id}";
	if (userId != null && userId.length > 0){
		$('#pwd').val("*********");
    	$('#repwd').val("*********");
	}
	$(function(){
		//未部门ID赋值
		$('#deptId').val($('#modelDeptId').val());
	});
</script>
</body>
</html>